<!DOCTYPE html
          PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html   xmlns   = "http://www.w3.org/1999/xhtml">
<head>
<link rel="STYLESHEET" href="filtersdk.css" type="text/css" />
<title>GeneralPurposeToMMXRegisters - AviSynth</title>
</head>
<BODY>

<div id="body">

<h1><a href="http://www.avisynth.org/GeneralPurposeToMMXRegisters" style="text-decoration:none">
    GeneralPurposeToMMXRegisters</a>
    	<p>
	</h1>

<p>It might be necessary to move data back and forth between a general purpose register 
(EAX for instance) to an MMX register. This can be done by:</p>


<p><tt>movd eax,mm0</tt></p>

<p><tt>movd mm0,eax</tt></p>

<p><tt>pinsrw mm0,eax,0</tt></p>

<p><tt>pextrw eax,mm0,0</tt></p>

<p><tt>movmskb eax,mm0</tt></p>


<p>These instructions should however <strong>be avoided as much as possible</strong> 
since they are executing very slow. It seems like there are severe penalties 
when moving data between the MMX registers and the general purpose registers. 
Most of these instructions take more than 16 cycles to execute, 
which is more than 8 times the cyclecount of normal MMX instructions.</p>


<p>In many cases it is actually faster to write the data to a temporary memory location, 
using movd, and move the data back into the registry. For much data 
it is actually often faster to process the data one line at the time, 
and store all data in a temporary space, and process the data in a separate loop.</p>


<hr />
<p><em>phaeron writes:</em></p>


<p>Note that the Microsoft Visual C++ compiler will give you trouble here if you are using MMX intrinsics, 
as it is unable to directly generate <tt>movd mmreg,mem</tt> and <tt>movd mem,mmreg</tt> 
instructions for the <tt>_m_to_int()</tt> and <tt>_m_from_int()</tt> intrinsics.  
Instead, the values trampoline off of the general purpose registers, triggering 
the undesirable performance behavior described above.  
This is true even with the Visual Studio .NET 2003 compiler (VC7.1), 
which fixed most of the MMX code generation embarrassments from the VC6PP and VC7 compilers, 
most notably MOVQ hell.  As such, you're still better off sticking with inline 
or explicit assembly than using MMX intrinsics with MSVC.</p>


<h4>Back to <a href="AssemblerOptimizing.htm">AssemblerOptimizing</a></h4></div>
<p><kbd>$Date: 2006/11/08 20:40:17 $<br>
Original version of this document <a href="http://www.avisynth.org/GeneralPurposeToMMXRegisters">http://www.avisynth.org/GeneralPurposeToMMXRegisters</a>
</kbd></p>
</BODY>
</html>
